package cn.com.headfree.drafts.service.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import cn.com.headfree.entity.*;
import cn.com.headfree.userinfo.service.IUserInfoService;
import cn.com.headfree.util.SysDictionaryUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gta.edu.sdk.common.dto.Page;
import com.gta.edu.sdk.util.IdGen;

import cn.com.headfree.drafts.dao.IDraftsDao;
import cn.com.headfree.drafts.service.IDraftsService;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.mouldshow.dao.HumanDataDao;
import cn.com.headfree.vo.EachTypeDetailVo;
import cn.com.headfree.vo.IntegrityAnalysisVo;
import cn.com.headfree.vo.SysDictionaryInfoVo;
import cn.com.headfree.vo.complex.TAcadeAchiveInfoVo;
import cn.com.headfree.vo.complex.TPatentInfoVo;
import cn.com.headfree.vo.complex.TProjAchieveInfoVo;
import cn.com.headfree.vo.complex.TStandInfoVo;
import cn.com.headfree.vo.complex.TTecInnovInfoVo;
import cn.com.headfree.vo.complex.TTecManInnovVo;
import cn.com.headfree.vo.drafts.DraftsListVo;

@Service("draftsService")
public class DraftsServiceImpl implements IDraftsService {

	@Autowired
	private IDraftsDao draftsDao;
	@Autowired
	private HumanDataDao humanDataDao;
	@Autowired
	private IUserInfoService userInfoService;

	// 基本信息
	@Value("${t_emp_base_info}")
	private String t_emp_base_info;
	// 年度绩效
	@Value("${t_year_effect_info}")
	private String t_year_effect_info;
	// 学历信息
	@Value("${t_educate_info}")
	private String t_educate_info;
	// 教育培训及授课经历
	@Value("${t_conti_study_info}")
	private String t_conti_study_info;
	// 专业技术资格
	@Value("${t_pro_tec_info}")
	private String t_pro_tec_info;
	// 技能等级信息
	@Value("${t_skill_level_info}")
	private String t_skill_level_info;
	// 专家人才称号
	@Value("${t_expert_title_info}")
	private String t_expert_title_info;
	// 学术成果
	@Value("${t_acade_achive_info}")
	private String t_acade_achive_info;
	// 制度标准
	@Value("${t_stand_info}")
	private String t_stand_info;
	// 专利信息
	@Value("${t_patent_info}")
	private String t_patent_info;
	// 技艺革新信息
	@Value("${t_tec_innov_info}")
	private String t_tec_innov_info;
	// 竞赛考试信息
	@Value("${t_contest_info}")
	private String t_contest_info;
	// 科技管理及创新成果
	@Value("${t_tec_man_innov}")
	private String t_tec_man_innov;
	// 个人荣誉
	@Value("${t_honor_info}")
	private String t_honor_info;
	// 项目课题成果
	@Value("${t_proj_achieve_info}")
	private String t_proj_achieve_info;
	// 导师带徒
	@Value("${t_sdt_tutor_prent_info}")
	private String t_sdt_tutor_prent_info;
	// 工作经历
	@Value("${t_work_exp_info}")
	private String t_work_exp_info;
	// 挂职轮岗
	@Value("${t_rotation_info}")
	private String t_rotation_info;
	// 挂职轮岗
	@Value("${t_employee_mobility}")
	private String t_employee_mobility;
	// 技术标准
	@Value("${t_tec_standard_info}")
	private String t_tec_standard_info;

	/**
	 * 基本信息添加和编辑
	 * 
	 * @param baseInfo
	 * @param user
	 */
	@Override
	public String addBaseInfo(TEmpBaseInfo baseInfo, User user) throws Exception {
		baseInfo.setUpdaterId(user.getFax());
		baseInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_emp_base_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		baseInfo.setCreaterId(user.getFax());
		baseInfo.setCreaterName(user.getName());
		baseInfo.setOrignalId(baseInfo.getId());
		baseInfo.setPrimitiveId(baseInfo.getId());
		baseInfo.setBusinessTypeId(t_emp_base_info);
		baseInfo.setDelSign(0);
//		if (user.getRemark().equals("2") || user.getRemark().equals("3")) {// 管理员
//			baseInfo.setIsValid(0);
//		} else {
			baseInfo.setIsValid(1);
			baseInfo.setFlowStatus(0);// 要审批
			// 先删除之前的审批流程
//					updateWorkFlowDataByPrimitiveId(baseInfo.getPrimitiveId());
//			addWorkFlowData(baseInfo.getId(), baseInfo.getPrimitiveId(), baseInfo.getAuditErpNo(), t_emp_base_info,
//					user.getFax(), dealRoleCode);
//		}
		draftsDao.addBaseInfo(baseInfo);
		// 新增插入操作记录
//		addRecordLogData(baseInfo.getId(), user, "0");
		return null;
	}

	@Override
	public TEmpBaseInfo getBaseInfoById(String id) {
		return draftsDao.getBaseInfoById(id);
	}

	@Override
	public TEmpBaseInfo getBaseInfoByErpNo(String erpNo) {
		return draftsDao.getBaseInfoByErpNo(erpNo);
	}

	/**
	 * 年度绩效
	 * 
	 * @param yearEffectInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addYearEffect(TYearEffectInfo yearEffectInfo, User user) throws Exception {
		yearEffectInfo.setUpdaterId(user.getFax());
		yearEffectInfo.setUpdaterName(user.getName());
		yearEffectInfo.setCreaterId(user.getFax());
		yearEffectInfo.setCreaterName(user.getName());
		yearEffectInfo.setOrignalId(yearEffectInfo.getId());
		yearEffectInfo.setPrimitiveId(yearEffectInfo.getId());
		yearEffectInfo.setBusinessTypeId(t_year_effect_info);
		yearEffectInfo.setDelSign(0);
		yearEffectInfo.setIsValid(0);
		yearEffectInfo.setFlowStatus(1);// 要审批
		draftsDao.addYearEffect(yearEffectInfo);
		return null;
	}

	@Override
	public TYearEffectInfo getYearEffectById(String id) {
		return draftsDao.getYearEffectById(id);
	}

	public List<TYearEffectInfo> getYearEffectByErpNo(String erpNo) {
		return draftsDao.getYearEffectByErpNo(erpNo);
	}

	@Override
	public void findPageYearEffectByCondi(Page<TYearEffectInfo> page, TYearEffectInfo tYearEffectInfo) {
		draftsDao.findPageYearEffectByCondi(page, tYearEffectInfo);
	}

	/**
	 * 学历信息
	 * 
	 * @param tEducateInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addEducateInfo(TEducateInfo tEducateInfo, User user) throws Exception {
		tEducateInfo.setUpdaterId(user.getFax());
		tEducateInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_educate_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tEducateInfo.setCreaterId(user.getFax());
		tEducateInfo.setCreaterName(user.getName());
		tEducateInfo.setOrignalId(tEducateInfo.getId());
		tEducateInfo.setPrimitiveId(tEducateInfo.getId());
		tEducateInfo.setBusinessTypeId(t_educate_info);
		tEducateInfo.setDelSign(0);
		tEducateInfo.setIsValid(1);
		tEducateInfo.setFlowStatus(0);// 要审批
		draftsDao.addEducateInfo(tEducateInfo);
		return null;
	}

	@Override
	public TEducateInfo getEducateInfoById(String id) {
		return draftsDao.getEducateInfoById(id);
	}

	@Override
	public List<TEducateInfo> getEducateInfoByErpNo(String erpNo, String isCountEduc) {
		return draftsDao.getEducateInfoByErpNo(erpNo, isCountEduc);
	}

	@Override
	public void findPageEducateInfoByCondi(Page<TEducateInfo> page, TEducateInfo tEducateInfo) {
		draftsDao.findPageEducateInfoByCondi(page, tEducateInfo);
	}

	/**
	 * 专业技术资格
	 * 
	 * @param tProTecInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addProTecInfo(TProTecInfo tProTecInfo, User user) throws Exception {
		tProTecInfo.setUpdaterId(user.getFax());
		tProTecInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_pro_tec_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tProTecInfo.setCreaterId(user.getFax());
		tProTecInfo.setCreaterName(user.getName());
		tProTecInfo.setOrignalId(tProTecInfo.getId());
		tProTecInfo.setPrimitiveId(tProTecInfo.getId());
		tProTecInfo.setBusinessTypeId(t_pro_tec_info);
		tProTecInfo.setDelSign(0);
		tProTecInfo.setIsValid(1);
		tProTecInfo.setFlowStatus(0);// 要审批
		draftsDao.addProTecInfo(tProTecInfo);
		return null;
	}

	@Override
	public TProTecInfo getProTecInfoById(String id) {
		return draftsDao.getProTecInfoById(id);
	}

	@Override
	public List<TProTecInfo> getProTecInfoByErpNo(String erpNo) {
		return draftsDao.getProTecInfoByErpNo(erpNo);
	}

	@Override
	public void findPageProTecInfoByCondi(Page<TProTecInfo> page, TProTecInfo tProTecInfo) {
		draftsDao.findPageProTecInfoByCondi(page, tProTecInfo);
	}

	/**
	 * 技能等级
	 * 
	 * @param tSkillLevelInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addSkillLevelInfo(TSkillLevelInfo tSkillLevelInfo, User user) throws Exception {
		tSkillLevelInfo.setUpdaterId(user.getFax());
		tSkillLevelInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_skill_level_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tSkillLevelInfo.setCreaterId(user.getFax());
		tSkillLevelInfo.setCreaterName(user.getName());
		tSkillLevelInfo.setOrignalId(tSkillLevelInfo.getId());
		tSkillLevelInfo.setPrimitiveId(tSkillLevelInfo.getId());
		tSkillLevelInfo.setBusinessTypeId(t_skill_level_info);
		tSkillLevelInfo.setDelSign(0);
		tSkillLevelInfo.setIsValid(1);
		tSkillLevelInfo.setFlowStatus(0);// 要审批
		draftsDao.addSkillLevelInfo(tSkillLevelInfo);
		return null;
	}

	@Override
	public TSkillLevelInfo getSkillLevelInfoById(String id) {
		return draftsDao.getTSkillLevelInfoById(id);
	}

	@Override
	public List<TSkillLevelInfo> getSkillLevelInfoByErpNo(String erpNo) {
		return draftsDao.getSkillLevelInfoByErpNo(erpNo);
	}

	@Override
	public void findPageSkillLevelInfoByCondi(Page<TSkillLevelInfo> page, TSkillLevelInfo tSkillLevelInfo) {
		draftsDao.findPageSkillLevelInfoByCondi(page, tSkillLevelInfo);
	}

	/**
	 * 专家人才称号
	 * 
	 * @param tExpertTitleInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addExpertTitleInfo(TExpertTitleInfo tExpertTitleInfo, User user) throws Exception {
		tExpertTitleInfo.setUpdaterId(user.getFax());
		tExpertTitleInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_expert_title_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tExpertTitleInfo.setCreaterId(user.getFax());
		tExpertTitleInfo.setCreaterName(user.getName());
		tExpertTitleInfo.setOrignalId(tExpertTitleInfo.getId());
		tExpertTitleInfo.setPrimitiveId(tExpertTitleInfo.getId());
		tExpertTitleInfo.setBusinessTypeId(t_expert_title_info);
		tExpertTitleInfo.setDelSign(0);
		tExpertTitleInfo.setIsValid(1);
		tExpertTitleInfo.setFlowStatus(0);// 要审批
		draftsDao.addExpertTitleInfo(tExpertTitleInfo);
		return null;
	}

	@Override
	public TExpertTitleInfo getExpertTitleInfoById(String id) {
		return draftsDao.getExpertTitleInfoById(id);
	}

	@Override
	public List<TExpertTitleInfo> getExpertTitleInfoByErpNo(String erpNo) {

		return draftsDao.getExpertTitleInfoByErpNo(erpNo);
	}

	@Override
	public void findPageExpertTitleInfoByCondi(Page<TExpertTitleInfo> page, TExpertTitleInfo tExpertTitleInfo) {
		draftsDao.findPageExpertTitleInfoByCondi(page, tExpertTitleInfo);
	}

	/**
	 * 学术成果
	 * 
	 * @param tAcadeAchiveInfo
	 * @param user
	 */
	@Override
	public String addAcadeAchiveInfo(TAcadeAchiveInfo tAcadeAchiveInfo, User user) throws Exception {
		tAcadeAchiveInfo.setUpdaterId(user.getFax());
		tAcadeAchiveInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_acade_achive_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		List<TPartRank> ranks = tAcadeAchiveInfo.gettPartRankList();
		// 普通人员新增的时候要判断参与人里面有没有当前登录人，如果没有就不允许添加
//			boolean flag = judgeTPartRankIsContainCurrentUser(ranks, user.getFax());
//			if (!flag) {
//				// 返回错误信息
//				String message = "当前添加的参与人员中没有包含当前登录人自己";
//				return message;
//			}
		tAcadeAchiveInfo.setCreaterId(user.getFax());
		tAcadeAchiveInfo.setCreaterName(user.getName());
		tAcadeAchiveInfo.setOrignalId(tAcadeAchiveInfo.getId());
		tAcadeAchiveInfo.setPrimitiveId(tAcadeAchiveInfo.getId());
		tAcadeAchiveInfo.setBusinessTypeId(t_acade_achive_info);
		tAcadeAchiveInfo.setDelSign(0);
		tAcadeAchiveInfo.setIsValid(1);
		tAcadeAchiveInfo.setFlowStatus(0);// 要审批
		draftsDao.addAcadeAchiveInfo(tAcadeAchiveInfo);
		addPartRank(ranks, tAcadeAchiveInfo.getId(), "12");
		return null;
	}

	@Override
	public TAcadeAchiveInfoVo getAcadeAchiveInfoById(String id) {
		TAcadeAchiveInfoVo tAcadeAchiveInfoVo = draftsDao.getAcadeAchiveInfoById(id);
		if (tAcadeAchiveInfoVo != null) {
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(new ArrayList<String>() {
				{
					add(id);
				}
			}, "12");
			tAcadeAchiveInfoVo.settPartRankList(tPartRankList);
		}
		return tAcadeAchiveInfoVo;
	}

	@Override
	public List<TAcadeAchiveInfoVo> getAcadeAchiveInfoByErpNo(String erpNo) {
		List<TAcadeAchiveInfoVo> tAcadeAchiveInfoVos = draftsDao.getAcadeAchiveInfoByErpNo(erpNo);

		if (tAcadeAchiveInfoVos.isEmpty()) {
			return tAcadeAchiveInfoVos;
		}
		List<String> ids = new ArrayList<>();
		tAcadeAchiveInfoVos.forEach(i -> ids.add(i.getId()));
		List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "12");
		if (!tPartRankList.isEmpty()) {
			for (TAcadeAchiveInfoVo tAcadeAchiveInfoVo : tAcadeAchiveInfoVos) {
				List<TPartRank> tPartRankListVo = new ArrayList<>();
				for (TPartRank tPartRank : tPartRankList) {
					if (tAcadeAchiveInfoVo.getId().equals(tPartRank.getItemId())) {
						tPartRankListVo.add(tPartRank);
					}
				}

				tAcadeAchiveInfoVo.settPartRankList(tPartRankListVo);
			}
		}
		return tAcadeAchiveInfoVos;
	}

	@Override
	public void findPageAcadeAchiveInfoByCondi(Page<TAcadeAchiveInfoVo> page, TAcadeAchiveInfo tAcadeAchiveInfo) {
		draftsDao.findPageAcadeAchiveInfoByCondi(page, tAcadeAchiveInfo);
		if (!page.getResult().isEmpty()) {
			List<TAcadeAchiveInfoVo> tAcadeAchiveInfoVos = page.getResult();

			List<String> ids = new ArrayList<>();
			tAcadeAchiveInfoVos.forEach(i -> ids.add(i.getId()));
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "12");
			if (!tPartRankList.isEmpty()) {
				for (TAcadeAchiveInfoVo tAcadeAchiveInfoVo : tAcadeAchiveInfoVos) {
					List<TPartRank> tPartRankListVo = new ArrayList<>();
					for (TPartRank tPartRank : tPartRankList) {
						if (tAcadeAchiveInfoVo.getId().equals(tPartRank.getItemId())) {
							tPartRankListVo.add(tPartRank);
						}
					}
					tAcadeAchiveInfoVo.settPartRankList(tPartRankListVo);
				}
			}
		}

	}

	/**
	 * 标准制定
	 * 
	 * @param tStandInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addStandInfo(TStandInfo tStandInfo, User user) throws Exception {
		tStandInfo.setUpdaterId(user.getFax());
		tStandInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_stand_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		List<TPartRank> ranks = tStandInfo.gettPartRankList();
		// 普通人员新增的时候要判断参与人里面有没有当前登录人，如果没有就不允许添加
//			boolean flag = judgeTPartRankIsContainCurrentUser(ranks, user.getFax());
//			if (!flag) {
//				// 返回错误信息
//				String message = "当前添加的参与人员中没有包含当前登录人自己";
//				return message;
//			}
		tStandInfo.setCreaterId(user.getFax());
		tStandInfo.setCreaterName(user.getName());
		tStandInfo.setOrignalId(tStandInfo.getId());
		tStandInfo.setPrimitiveId(tStandInfo.getId());
		tStandInfo.setBusinessTypeId(t_stand_info);
		tStandInfo.setDelSign(0);
		tStandInfo.setIsValid(1);
		tStandInfo.setFlowStatus(0);// 要审批
		draftsDao.addStandInfo(tStandInfo);
		addPartRank(ranks, tStandInfo.getId(), "13");
		return null;
	}

	@Override
	public TStandInfoVo getStandInfoById(String id) {
		TStandInfoVo tStandInfoVo = draftsDao.getStandInfoById(id);
		if (tStandInfoVo != null) {
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(new ArrayList<String>() {
				{
					add(id);
				}
			}, "13");
			tStandInfoVo.settPartRankList(tPartRankList);
		}
		return tStandInfoVo;
	}

	@Override
	public List<TStandInfoVo> getStandInfoByErpNo(String erpNo) {
		List<TStandInfoVo> tStandInfoVos = draftsDao.getStandInfoByErpNo(erpNo);
		if (tStandInfoVos.isEmpty()) {
			return tStandInfoVos;
		}
		List<String> ids = new ArrayList<>();
		tStandInfoVos.forEach(i -> ids.add(i.getId()));
		List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "13");
		if (!tPartRankList.isEmpty()) {
			for (TStandInfoVo tStandInfoVo : tStandInfoVos) {
				List<TPartRank> tPartRankListVo = new ArrayList<>();
				for (TPartRank tPartRank : tPartRankList) {
					if (tStandInfoVo.getId().equals(tPartRank.getItemId())) {
						tPartRankListVo.add(tPartRank);
					}
				}

				tStandInfoVo.settPartRankList(tPartRankListVo);
			}
		}
		return tStandInfoVos;

	}

	@Override
	public void findPageStandInfoByCondi(Page<TStandInfoVo> page, TStandInfo tStandInfo) {
		draftsDao.findPageStandInfoByCondi(page, tStandInfo);
		if (!page.getResult().isEmpty()) {
			List<TStandInfoVo> tStandInfoVos = page.getResult();

			List<String> ids = new ArrayList<>();
			tStandInfoVos.forEach(i -> ids.add(i.getId()));
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "13");
			if (!tPartRankList.isEmpty()) {
				for (TStandInfoVo tStandInfoVo : tStandInfoVos) {
					List<TPartRank> tPartRankListVo = new ArrayList<>();
					for (TPartRank tPartRank : tPartRankList) {
						if (tStandInfoVo.getId().equals(tPartRank.getItemId())) {
							tPartRankListVo.add(tPartRank);
						}
					}

					tStandInfoVo.settPartRankList(tPartRankListVo);
				}
			}
		}
	}

	/**
	 * 专利信息
	 * 
	 * @param tPatentInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addPatentInfo(TPatentInfo tPatentInfo, User user) throws Exception {
		tPatentInfo.setUpdaterId(user.getFax());
		tPatentInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_patent_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		List<TPartRank> ranks = tPatentInfo.gettPartRankList();
		// 普通人员新增的时候要判断参与人里面有没有当前登录人，如果没有就不允许添加
//			boolean flag = judgeTPartRankIsContainCurrentUser(ranks, user.getFax());
//			if (!flag) {
//				// 返回错误信息
//				String message = "当前添加的参与人员中没有包含当前登录人自己";
//				return message;
//			}
		tPatentInfo.setCreaterId(user.getFax());
		tPatentInfo.setCreaterName(user.getName());
		tPatentInfo.setOrignalId(tPatentInfo.getId());
		tPatentInfo.setPrimitiveId(tPatentInfo.getId());
		tPatentInfo.setBusinessTypeId(t_patent_info);
		tPatentInfo.setDelSign(0);
		tPatentInfo.setIsValid(1);// 无效
		tPatentInfo.setFlowStatus(0);// 要审批
		draftsDao.addPatentInfo(tPatentInfo);
		addPartRank(ranks, tPatentInfo.getId(), "14");
		return null;
	}

	@Override
	public TPatentInfoVo getPatentInfoById(String id) {
		TPatentInfoVo tPatentInfoVo = draftsDao.getPatentInfoById(id);
		if (tPatentInfoVo != null) {
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(new ArrayList<String>() {
				{
					add(id);
				}
			}, "14");
			tPatentInfoVo.settPartRankList(tPartRankList);
		}
		return tPatentInfoVo;
	}

	@Override
	public List<TPatentInfoVo> getPatentInfoByErpNo(String erpNo) {

		List<TPatentInfoVo> tPatentInfoVos = draftsDao.getPatentInfoByErpNo(erpNo);
		if (tPatentInfoVos.isEmpty()) {
			return tPatentInfoVos;
		}
		List<String> ids = new ArrayList<>();
		tPatentInfoVos.forEach(i -> ids.add(i.getId()));
		List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "14");
		if (!tPatentInfoVos.isEmpty()) {
			for (TPatentInfoVo tPatentInfoVo : tPatentInfoVos) {
				List<TPartRank> tPartRankVo = new ArrayList<>();
				for (TPartRank tPartRank : tPartRankList) {
					if (tPatentInfoVo.getId().equals(tPartRank.getItemId())) {
						tPartRankVo.add(tPartRank);
					}
				}

				tPatentInfoVo.settPartRankList(tPartRankVo);
			}
		}

		return tPatentInfoVos;
	}

	@Override
	public void findPagePatentInfoByCondi(Page<TPatentInfoVo> page, TPatentInfo tPatentInfo) {
		draftsDao.findPagePatentInfoByCondi(page, tPatentInfo);
		if (!page.getResult().isEmpty()) {
			List<TPatentInfoVo> tPatentInfoVos = page.getResult();

			List<String> ids = new ArrayList<>();
			tPatentInfoVos.forEach(i -> ids.add(i.getId()));
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "14");
			if (!tPatentInfoVos.isEmpty()) {
				for (TPatentInfoVo tPatentInfoVo : tPatentInfoVos) {
					List<TPartRank> tPartRankVo = new ArrayList<>();
					for (TPartRank tPartRank : tPartRankList) {
						if (tPatentInfoVo.getId().equals(tPartRank.getItemId())) {
							tPartRankVo.add(tPartRank);
						}
					}

					tPatentInfoVo.settPartRankList(tPartRankVo);
				}
			}
		}
	}

	/**
	 * 技艺革新
	 * 
	 * @param tTecInnovInfo
	 * @param user
	 * @throws Exception
	 */

	@Override
	public String addTecInnovInfo(TTecInnovInfo tTecInnovInfo, User user) throws Exception {
		tTecInnovInfo.setUpdaterId(user.getFax());
		tTecInnovInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_tec_innov_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		List<TPartRank> ranks = tTecInnovInfo.gettPartRankList();
		// 普通人员新增的时候要判断参与人里面有没有当前登录人，如果没有就不允许添加
//			boolean flag = judgeTPartRankIsContainCurrentUser(ranks, user.getFax());
//			if (!flag) {
//				// 返回错误信息
//				String message = "当前添加的参与人员中没有包含当前登录人自己";
//				return message;
//			}
		tTecInnovInfo.setCreaterId(user.getFax());
		tTecInnovInfo.setCreaterName(user.getName());
		tTecInnovInfo.setOrignalId(tTecInnovInfo.getId());
		tTecInnovInfo.setPrimitiveId(tTecInnovInfo.getId());
		tTecInnovInfo.setBusinessTypeId(t_tec_innov_info);
		tTecInnovInfo.setDelSign(0);
		tTecInnovInfo.setIsValid(1);// 无效
		tTecInnovInfo.setFlowStatus(0);// 要审批
		draftsDao.addTecInnovInfo(tTecInnovInfo);
		addPartRank(ranks, tTecInnovInfo.getId(), "15");
		return null;
	}

	@Override
	public TTecInnovInfoVo getTecInnovInfoById(String id) {
		TTecInnovInfoVo tTecInnovInfoVo = draftsDao.getTecInnovInfoById(id);
		if (tTecInnovInfoVo != null) {
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(new ArrayList<String>() {
				{
					add(id);
				}
			}, "15");
			tTecInnovInfoVo.settPartRankList(tPartRankList);
		}
		return tTecInnovInfoVo;
	}

	@Override
	public List<TTecInnovInfoVo> getTecInnovInfoByErpNo(String erpNo) {

		List<TTecInnovInfoVo> tTecInnovInfoVos = draftsDao.getTecInnovInfoByErpNo(erpNo);
		if (tTecInnovInfoVos.isEmpty()) {
			return tTecInnovInfoVos;
		}
		List<String> ids = new ArrayList<>();
		tTecInnovInfoVos.forEach(i -> ids.add(i.getId()));
		List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "15");
		if (!tPartRankList.isEmpty()) {
			for (TTecInnovInfoVo tTecInnovInfoVo : tTecInnovInfoVos) {
				List<TPartRank> tPartRankListVo = new ArrayList<>();
				for (TPartRank tPartRank : tPartRankList) {
					if (tTecInnovInfoVo.getId().equals(tPartRank.getItemId())) {
						tPartRankListVo.add(tPartRank);
					}
				}

				tTecInnovInfoVo.settPartRankList(tPartRankListVo);
			}
		}

		return tTecInnovInfoVos;
	}

	@Override
	public void findPageTecInnovInfoByCondi(Page<TTecInnovInfoVo> page, TTecInnovInfo tTecInnovInfo) {
		draftsDao.findPageTecInnovInfoByCondi(page, tTecInnovInfo);
		if (!page.getResult().isEmpty()) {
			List<TTecInnovInfoVo> tTecInnovInfoVos = page.getResult();

			List<String> ids = new ArrayList<>();
			tTecInnovInfoVos.forEach(i -> ids.add(i.getId()));
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "15");
			if (!tPartRankList.isEmpty()) {
				for (TTecInnovInfoVo tTecInnovInfoVo : tTecInnovInfoVos) {
					List<TPartRank> tPartRankListVo = new ArrayList<>();
					for (TPartRank tPartRank : tPartRankList) {
						if (tTecInnovInfoVo.getId().equals(tPartRank.getItemId())) {
							tPartRankListVo.add(tPartRank);
						}
					}

					tTecInnovInfoVo.settPartRankList(tPartRankListVo);
				}
			}
		}
	}

	/**
	 * 竞赛考试
	 * 
	 * @param tContestInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addContestInfo(TContestInfo tContestInfo, User user) throws Exception {
		tContestInfo.setUpdaterId(user.getFax());
		tContestInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_contest_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tContestInfo.setCreaterId(user.getFax());
		tContestInfo.setCreaterName(user.getName());
		tContestInfo.setOrignalId(tContestInfo.getId());
		tContestInfo.setPrimitiveId(tContestInfo.getId());
		tContestInfo.setBusinessTypeId(t_contest_info);
		tContestInfo.setDelSign(0);
		tContestInfo.setIsValid(1);// 无效
		tContestInfo.setFlowStatus(0);// 要审批
		draftsDao.addContestInfo(tContestInfo);
		return null;
	}

	@Override
	public TContestInfo getContestInfoById(String id) {
		return draftsDao.getContestInfoById(id);
	}

	@Override
	public List<TContestInfo> getContestInfoByErpNo(String erpNo) {
		return draftsDao.getContestInfoByErpNo(erpNo);
	}

	@Override
	public void findPageContestInfoByCondi(Page<TContestInfo> page, TContestInfo tContestInfo) {
		draftsDao.findPageContestInfoByCondi(page, tContestInfo);
	}

	/**
	 * 科技创新成果
	 * 
	 * @param tTecManInnov
	 * @param user
	 */
	@Override
	public String addTecManInnov(TTecManInnov tTecManInnov, User user) throws Exception {
		tTecManInnov.setUpdaterId(user.getFax());
		tTecManInnov.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_tec_man_innov, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		List<TPartRank> ranks = tTecManInnov.gettPartRankList();
		// 普通人员新增的时候要判断参与人里面有没有当前登录人，如果没有就不允许添加
//			boolean flag = judgeTPartRankIsContainCurrentUser(ranks, user.getFax());
//			if (!flag) {
//				// 返回错误信息
//				String message = "当前添加的参与人员中没有包含当前登录人自己";
//				return message;
//			}
		tTecManInnov.setCreaterId(user.getFax());
		tTecManInnov.setCreaterName(user.getName());
		tTecManInnov.setOrignalId(tTecManInnov.getId());
		tTecManInnov.setPrimitiveId(tTecManInnov.getId());
		tTecManInnov.setBusinessTypeId(t_tec_man_innov);
		tTecManInnov.setDelSign(0);
		tTecManInnov.setIsValid(1);// 无效
		tTecManInnov.setFlowStatus(0);// 要审批
		draftsDao.addTecManInnov(tTecManInnov);
		addPartRank(ranks, tTecManInnov.getId(), "16");
		return null;
	}

	@Override
	public TTecManInnovVo getTecManInnovById(String id) {
		TTecManInnovVo tTecManInnovVo = draftsDao.getTecManInnovById(id);
		if (tTecManInnovVo != null) {
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(new ArrayList<String>() {
				{
					add(id);
				}
			}, "16");
			tTecManInnovVo.settPartRankList(tPartRankList);
		}
		return tTecManInnovVo;
	}

	@Override
	public List<TTecManInnovVo> getTecManInnovByErpNo(String erpNo) {

		List<TTecManInnovVo> tTecManInnovVos = draftsDao.getTecManInnovByErpNo(erpNo);

		if (tTecManInnovVos.isEmpty()) {
			return tTecManInnovVos;
		}
		List<String> ids = new ArrayList<>();
		tTecManInnovVos.forEach(i -> ids.add(i.getId()));
		List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "16");
		if (!tPartRankList.isEmpty()) {
			for (TTecManInnovVo tTecManInnovVo : tTecManInnovVos) {
				List<TPartRank> tPartRankListVo = new ArrayList<>();
				for (TPartRank tPartRank : tPartRankList) {
					if (tTecManInnovVo.getId().equals(tPartRank.getItemId())) {
						tPartRankListVo.add(tPartRank);
					}
				}

				tTecManInnovVo.settPartRankList(tPartRankListVo);
			}
		}

		return tTecManInnovVos;
	}

	@Override
	public void findPageTecManInnovByCondi(Page<TTecManInnovVo> page, TTecManInnov tTecManInnov) {
		draftsDao.findPageTecManInnovByCondi(page, tTecManInnov);
		if (!page.getResult().isEmpty()) {
			List<TTecManInnovVo> tTecManInnovVos = page.getResult();

			List<String> ids = new ArrayList<>();
			tTecManInnovVos.forEach(i -> ids.add(i.getId()));
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "16");
			if (!tPartRankList.isEmpty()) {
				for (TTecManInnovVo tTecManInnovVo : tTecManInnovVos) {
					List<TPartRank> tPartRankListVo = new ArrayList<>();
					for (TPartRank tPartRank : tPartRankList) {
						if (tTecManInnovVo.getId().equals(tPartRank.getItemId())) {
							tPartRankListVo.add(tPartRank);
						}
					}

					tTecManInnovVo.settPartRankList(tPartRankListVo);
				}
			}
		}
	}

	/**
	 * 个人荣誉
	 * 
	 * @param tHonorInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addHonorInfo(THonorInfo tHonorInfo, User user) throws Exception {
		tHonorInfo.setUpdaterId(user.getFax());
		tHonorInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_honor_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tHonorInfo.setCreaterId(user.getFax());
		tHonorInfo.setCreaterName(user.getName());
		tHonorInfo.setOrignalId(tHonorInfo.getId());
		tHonorInfo.setPrimitiveId(tHonorInfo.getId());
		tHonorInfo.setBusinessTypeId(t_honor_info);
		tHonorInfo.setDelSign(0);
		tHonorInfo.setIsValid(1);// 无效
		tHonorInfo.setFlowStatus(0);// 要审批
		draftsDao.addHonorInfo(tHonorInfo);
		return null;
	}

	@Override
	public THonorInfo getHonorInfoById(String id) {
		return draftsDao.getHonorInfoById(id);
	}

	@Override
	public List<THonorInfo> getHonnorInfoByErpNo(String erpNo) {
		return draftsDao.getHonnorInfoByErpNo(erpNo);
	}

	@Override
	public void findPageHonorInfoByCondi(Page<THonorInfo> page, THonorInfo tHonorInfo) {
		draftsDao.findPageHonorInfoByCondi(page, tHonorInfo);
	}

	/**
	 * 工作经历
	 * 
	 * @param tWorkExpInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addWorkExpInfo(TWorkExpInfo tWorkExpInfo, User user) throws Exception {
		tWorkExpInfo.setUpdaterId(user.getFax());
		tWorkExpInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_work_exp_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tWorkExpInfo.setCreaterId(user.getFax());
		tWorkExpInfo.setCreaterName(user.getName());
		tWorkExpInfo.setOrignalId(tWorkExpInfo.getId());
		tWorkExpInfo.setPrimitiveId(tWorkExpInfo.getId());
		tWorkExpInfo.setBusinessTypeId(t_work_exp_info);
		tWorkExpInfo.setDelSign(0);
//		if (user.getRemark().equals("2") || user.getRemark().equals("3")) {// 管理员
//			tWorkExpInfo.setIsValid(0);// 有效
//		} else {
			tWorkExpInfo.setIsValid(1);// 无效
			tWorkExpInfo.setFlowStatus(0);// 要审批
//			// 先删除之前的审批流程
////					updateWorkFlowDataByPrimitiveId(tWorkExpInfo.getPrimitiveId());
//			addWorkFlowData(tWorkExpInfo.getId(), tWorkExpInfo.getPrimitiveId(), tWorkExpInfo.getAuditErpNo(),
//					t_work_exp_info, user.getFax(), dealRoleCode);
//		}
		draftsDao.addWorkExpInfo(tWorkExpInfo);
		// 新增插入操作记录
//		addRecordLogData(tWorkExpInfo.getId(), user, "0");
		return null;
	}

	@Override
	public TWorkExpInfo getWorkExpInfoById(String id) {
		return draftsDao.getWorkExpInfoById(id);
	}

	@Override
	public List<TWorkExpInfo> getWorkExpInfoByErpNo(String erpNo) {
		return draftsDao.getWorkExpInfoByErpNo(erpNo);
	}

	@Override
	public void findPageWorkExpInfoByCondi(Page<TWorkExpInfo> page, TWorkExpInfo tWorkExpInfo) {
		draftsDao.findPageWorkExpInfoByCondi(page, tWorkExpInfo);
	}

	/**
	 * 教育培训及授课
	 * 
	 * @param tContiStudyInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addContiStudyInfo(TContiStudyInfo tContiStudyInfo, User user) throws Exception {
		tContiStudyInfo.setUpdaterId(user.getFax());
		tContiStudyInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_conti_study_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tContiStudyInfo.setCreaterId(user.getFax());
		tContiStudyInfo.setCreaterName(user.getName());
		tContiStudyInfo.setOrignalId(tContiStudyInfo.getId());
		tContiStudyInfo.setPrimitiveId(tContiStudyInfo.getId());
		tContiStudyInfo.setBusinessTypeId(t_conti_study_info);
		tContiStudyInfo.setDelSign(0);
		tContiStudyInfo.setIsValid(1);// 无效
		tContiStudyInfo.setFlowStatus(0);// 要审批
		draftsDao.addContiStudyInfo(tContiStudyInfo);
		return null;
	}

	@Override
	public TContiStudyInfo getContiStudyInfoById(String id) {
		return draftsDao.getContiStudyInfoById(id);
	}

	@Override
	public List<TContiStudyInfo> getContiStudyInfoByErpNo(String erpNo) {
		return draftsDao.getContiStudyInfoByErpNo(erpNo);
	}

	@Override
	public void findPageContiStudyInfoByCondi(Page<TContiStudyInfo> page, TContiStudyInfo tContiStudyInfo) {
		draftsDao.findPageContiStudyInfoByCondi(page, tContiStudyInfo);
	}

	/**
	 * 师带徒信息
	 * 
	 * @param tSdtTutorPrentInfo
	 * @param user
	 * @throws Exception
	 */
	@Override
	public String addSdtTutorPrentInfo(TSdtTutorPrentInfo tSdtTutorPrentInfo, User user) throws Exception {
		tSdtTutorPrentInfo.setUpdaterId(user.getFax());
		tSdtTutorPrentInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_sdt_tutor_prent_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		List<TSdtPrentInfo> prents = tSdtTutorPrentInfo.gettSdtPrentInfo();
		tSdtTutorPrentInfo.setCreaterId(user.getFax());
		tSdtTutorPrentInfo.setCreaterName(user.getName());
		tSdtTutorPrentInfo.setOrignalId(tSdtTutorPrentInfo.getId());
		tSdtTutorPrentInfo.setPrimitiveId(tSdtTutorPrentInfo.getId());
		tSdtTutorPrentInfo.setBusinessTypeId(t_sdt_tutor_prent_info);
		tSdtTutorPrentInfo.setDelSign(0);
		tSdtTutorPrentInfo.setIsValid(1);// 无效
		tSdtTutorPrentInfo.setFlowStatus(0);// 要审批
		draftsDao.addSdtTutorPrentInfo(tSdtTutorPrentInfo);
		// 插入徒弟信息及土地所获奖项信息，管理员新增、普通人员新增、修改时都是新增；
		// 管理员修改时只是修改，先将原徒弟信息和徒弟所获奖项删除，然后再新增
		if (prents.size() > 0) {
			prents.forEach(p -> {
				p.setId(IdGen.uuid());
				p.setSdtId(tSdtTutorPrentInfo.getId());
				p.setCreaterId(user.getFax());
				p.setCreaterName(user.getName());
				p.setDelSign(0);
				draftsDao.addSdtPrentInfo(p);
				List<TSdtAward> tSdtAwards = p.gettSdtAwardList();
				if (tSdtAwards != null && tSdtAwards.size() > 0) {
					tSdtAwards.forEach(t -> {
						t.setId(IdGen.uuid());
						t.setSdtTdId(p.getId());
						t.setCreaterId(user.getFax());
						t.setCreaterName(user.getName());
						t.setUpdaterId(user.getFax());
						t.setUpdaterName(user.getName());
						draftsDao.addSdtAwardInfo(t);
					});
				}
			});
		}
		return null;
	}

	@Override
	public TSdtTutorPrentInfo getSdtTutorPrentInfoById(String id) {
		TSdtTutorPrentInfo tSdtTutorPrentInfo = draftsDao.getSdtTutorPrentInfoById(id);

		if (tSdtTutorPrentInfo != null) {
			List<TSdtPrentInfo> tSdtPrentInfos = draftsDao.getTSdtPrentInfoByMids(new ArrayList<String>() {
				{
					add(tSdtTutorPrentInfo.getId());
				}
			});
			// 徒弟所获奖项
			if (tSdtPrentInfos != null && tSdtPrentInfos.size() > 0) {
				tSdtPrentInfos.forEach(p -> {
					List<TSdtAward> tSdtAwards = draftsDao.getSdtAwardBySdtTdId(p.getId());
					p.settSdtAwardList(tSdtAwards);
				});
			}
			tSdtTutorPrentInfo.settSdtPrentInfo(tSdtPrentInfos);
		}
		return tSdtTutorPrentInfo;
	}

	@Override
	public List<TSdtTutorPrentInfo> getSdtTutorPrentInfoByErpNo(String erpNo) {
		List<TSdtTutorPrentInfo> tSdtTutorPrentInfos = draftsDao.getSdtTutorPrentInfoByErpNo(erpNo);

		if (tSdtTutorPrentInfos.isEmpty()) {
			return tSdtTutorPrentInfos;
		}
		List<String> ids = new ArrayList<>();
		tSdtTutorPrentInfos.forEach(i -> ids.add(i.getId()));
		List<TSdtPrentInfo> tSdtPrentInfoList = draftsDao.getTSdtPrentInfoByMids(ids);
		if (!tSdtPrentInfoList.isEmpty()) {

			List<String> prentIds = new ArrayList<>();
			tSdtPrentInfoList.forEach(i -> prentIds.add(i.getId()));
			List<TSdtAward> tSdtAwardList = draftsDao.getTSdtAwardByMids(prentIds);

			for (TSdtTutorPrentInfo tutorPrentInfo : tSdtTutorPrentInfos) {
				List<TSdtPrentInfo> tSdtPrentInfos = new ArrayList<>();
				for (TSdtPrentInfo tSdtPrentInfo : tSdtPrentInfoList) {

					if (!tSdtAwardList.isEmpty()) {
						List<TSdtAward> tSdtAwards = new ArrayList<>();
						for (TSdtAward tSdtAward : tSdtAwardList) {
							if (tSdtAward.getSdtTdId().equals(tSdtPrentInfo.getId())) {
								tSdtAwards.add(tSdtAward);
							}
						}

						tSdtPrentInfo.settSdtAwardList(tSdtAwards);
					}

					if (tutorPrentInfo.getId().equals(tSdtPrentInfo.getSdtId())) {
						tSdtPrentInfos.add(tSdtPrentInfo);
					}
				}

				tutorPrentInfo.settSdtPrentInfo(tSdtPrentInfos);
			}
		}
		return tSdtTutorPrentInfos;
	}

	@Override
	public void findPageSdtTutorPrentInfoByCondi(Page<TSdtTutorPrentInfo> page, TSdtTutorPrentInfo tSdtTutorPrentInfo) {
		draftsDao.findPageSdtTutorPrentInfoByCondi(page, tSdtTutorPrentInfo);

		if (!page.getResult().isEmpty()) {
			List<TSdtTutorPrentInfo> tSdtTutorPrentInfos = page.getResult();

			List<String> ids = new ArrayList<>();
			tSdtTutorPrentInfos.forEach(i -> ids.add(i.getId()));
			List<TSdtPrentInfo> tSdtPrentInfoList = draftsDao.getTSdtPrentInfoByMids(ids);

			if (!tSdtPrentInfoList.isEmpty()) {
				List<String> prentIds = new ArrayList<>();
				tSdtPrentInfoList.forEach(i -> prentIds.add(i.getId()));
				List<TSdtAward> tSdtAwardList = draftsDao.getTSdtAwardByMids(prentIds);

				for (TSdtTutorPrentInfo tutorPrentInfo : tSdtTutorPrentInfos) {
					List<TSdtPrentInfo> tSdtPrentInfos = new ArrayList<>();
					for (TSdtPrentInfo tSdtPrentInfo : tSdtPrentInfoList) {

						if (!tSdtAwardList.isEmpty()) {
							List<TSdtAward> tSdtAwards = new ArrayList<>();
							for (TSdtAward tSdtAward : tSdtAwardList) {
								if (tSdtAward.getSdtTdId().equals(tSdtPrentInfo.getId())) {
									tSdtAwards.add(tSdtAward);
								}
							}

							tSdtPrentInfo.settSdtAwardList(tSdtAwards);
						}

						if (tutorPrentInfo.getId().equals(tSdtPrentInfo.getSdtId())) {
							tSdtPrentInfos.add(tSdtPrentInfo);
						}
					}

					tutorPrentInfo.settSdtPrentInfo(tSdtPrentInfos);
				}
			}
		}

	}

	/**
	 * 项目课题成果
	 * 
	 * @param tProjAchieveInfo
	 * @param user
	 */
	@Override
	public String addProjAchieveInfo(TProjAchieveInfo tProjAchieveInfo, User user) throws Exception {
		tProjAchieveInfo.setUpdaterId(user.getFax());
		tProjAchieveInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {// 普通人员
//			dealRoleCode = getDealRoleId(t_proj_achieve_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		List<TPartRank> ranks = tProjAchieveInfo.gettPartRankList();
		// 普通人员新增的时候要判断参与人里面有没有当前登录人，如果没有就不允许添加
//			boolean flag = judgeTPartRankIsContainCurrentUser(ranks, user.getFax());
//			if (!flag) {
//				// 返回错误信息
//				String message = "当前添加的参与人员中没有包含当前登录人自己";
//				return message;
//			}
		tProjAchieveInfo.setCreaterId(user.getFax());
		tProjAchieveInfo.setCreaterName(user.getName());
		tProjAchieveInfo.setOrignalId(tProjAchieveInfo.getId());
		tProjAchieveInfo.setPrimitiveId(tProjAchieveInfo.getId());
		tProjAchieveInfo.setBusinessTypeId(t_proj_achieve_info);
		tProjAchieveInfo.setDelSign(0);
		tProjAchieveInfo.setIsValid(1);// 无效
		tProjAchieveInfo.setFlowStatus(0);// 要审批
		draftsDao.addProjAchieveInfo(tProjAchieveInfo);
		addPartRank(ranks, tProjAchieveInfo.getId(), "17");
		return null;
	}

	@Override
	public TProjAchieveInfoVo getProjAchieveInfoById(String id) {
		TProjAchieveInfoVo tProjAchieveInfoVo = draftsDao.getProjAchieveInfoById(id);
		if (tProjAchieveInfoVo != null) {
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(new ArrayList<String>() {
				{
					add(tProjAchieveInfoVo.getId());
				}
			}, "17");
			tProjAchieveInfoVo.settPartRankList(tPartRankList);
		}
		return tProjAchieveInfoVo;
	}

	@Override
	public List<TProjAchieveInfoVo> getProjAchieveInfoByErpNo(String erpNo) {
		List<TProjAchieveInfoVo> tProjAchieveInfoVos = draftsDao.getProjAchieveInfoByErpNo(erpNo);
		if (tProjAchieveInfoVos.isEmpty()) {
			return tProjAchieveInfoVos;
		}
		List<String> ids = new ArrayList<>();
		tProjAchieveInfoVos.forEach(i -> ids.add(i.getId()));
		List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "17");
		if (!tPartRankList.isEmpty()) {
			for (TProjAchieveInfoVo tProjAchieveInfoVo : tProjAchieveInfoVos) {
				List<TPartRank> tPartRankListVo = new ArrayList<>();
				for (TPartRank tPartRank : tPartRankList) {
					if (tProjAchieveInfoVo.getId().equals(tPartRank.getItemId())) {
						tPartRankListVo.add(tPartRank);
					}
				}

				tProjAchieveInfoVo.settPartRankList(tPartRankListVo);
			}
		}

		return tProjAchieveInfoVos;

	}

	@Override
	public void findPageProjAchieveInfoByCondi(Page<TProjAchieveInfoVo> page, TProjAchieveInfo tProjAchieveInfo) {
		draftsDao.findPageProjAchieveInfoByCondi(page, tProjAchieveInfo);
		if (!page.getResult().isEmpty()) {
			List<TProjAchieveInfoVo> tProjAchieveInfoVos = page.getResult();

			if (tProjAchieveInfoVos.isEmpty()) {
				return;
			}
			List<String> ids = new ArrayList<>();
			tProjAchieveInfoVos.forEach(i -> ids.add(i.getId()));
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "17");
			if (!tPartRankList.isEmpty()) {
				for (TProjAchieveInfoVo tProjAchieveInfoVo : tProjAchieveInfoVos) {
					List<TPartRank> tPartRankListVo = new ArrayList<>();
					for (TPartRank tPartRank : tPartRankList) {
						if (tProjAchieveInfoVo.getId().equals(tPartRank.getItemId())) {
							tPartRankListVo.add(tPartRank);
						}
					}

					tProjAchieveInfoVo.settPartRankList(tPartRankListVo);
				}
			}
		}
	}

	@Override
	public List<TMouldInfo> getMouldInfoList(TMouldInfo tMouldInfo) {
		return draftsDao.getMouldInfoList(tMouldInfo);
	}

	@Override
	public void getEachTypeDetailList(EachTypeDetailVo detail, Page<EachTypeDetailVo> page) {
		draftsDao.getEachTypeDetailList(detail, page);
	}

	@Override
	public List<SysDictionaryInfoVo> getAttendanceUserTypeByValue(String value) {
		return draftsDao.getAttendanceUserTypeByValue(value);
	}

	/****************************************
	 * 通过数据id判断当前数据是否存在待审核的副本数据
	 ********************************/

	@Override
	public List<TYearEffectInfo> getReadyYearEffectById(String id) {
		return draftsDao.getReadyYearEffectById(id);
	}

	@Override
	public List<TEducateInfo> getReadyEducateInfoById(String id) {
		return draftsDao.getReadyEducateInfoById(id);
	}

	@Override
	public List<TProTecInfo> getReadyProTecInfoById(String id) {
		return draftsDao.getReadyProTecInfoById(id);
	}

	@Override
	public List<TSkillLevelInfo> getReadySkillLevelInfoById(String id) {
		return draftsDao.getReadySkillLevelInfoById(id);
	}

	@Override
	public List<TExpertTitleInfo> getReadyExpertTitleInfoById(String id) {
		return draftsDao.getReadyExpertTitleInfoById(id);
	}

	@Override
	public List<TAcadeAchiveInfo> getReadyAcadeAchiveInfoById(String id) {
		return draftsDao.getReadyAcadeAchiveInfoById(id);
	}

	@Override
	public List<TStandInfo> getReadyStandInfoById(String id) {
		return draftsDao.getReadyStandInfoById(id);
	}

	@Override
	public List<TPatentInfo> getReadyPatentInfoById(String id) {
		return draftsDao.getReadyPatentInfoById(id);
	}

	@Override
	public List<TTecInnovInfo> getReadyTecInnovInfoById(String id) {
		return draftsDao.getReadyTecInnovInfoById(id);
	}

	@Override
	public List<TContestInfo> getReadyContestInfoById(String id) {
		return draftsDao.getReadyContestInfoById(id);
	}

	@Override
	public List<TTecManInnov> getReadyTecManInnovById(String id) {
		return draftsDao.getReadyTecManInnovById(id);
	}

	@Override
	public List<THonorInfo> getReadyHonorInfoById(String id) {
		return draftsDao.getReadyHonorInfoById(id);
	}

	@Override
	public List<TWorkExpInfo> getReadyWorkExpInfoById(String id) {
		return draftsDao.getReadyWorkExpInfoById(id);
	}

	@Override
	public List<TContiStudyInfo> getReadyContiStudyInfoById(String id) {
		return draftsDao.getReadyContiStudyInfoById(id);
	}

	@Override
	public List<TSdtTutorPrentInfo> getReadySdtTutorPrentInfoById(String id) {
		return draftsDao.getReadySdtTutorPrentInfoById(id);
	}

	@Override
	public List<TProjAchieveInfo> getReadyProjAchieveInfoById(String id) {
		return draftsDao.getReadyProjAchieveInfoById(id);
	}

	/**
	 * 参与人员新增
	 * 
	 * @param ranks
	 * @param id
	 * @param type
	 */
	public void addPartRank(List<TPartRank> ranks, String id, String type) {
		if (ranks.size() > 0) {
			ranks.forEach(p -> {
				p.setId(IdGen.uuid());
				p.setItemId(id);
				p.setItemType(type);
				p.setIsValid(1);// 无效
				draftsDao.addPartRank(p);
			});
		}
	}

	/**
	 * 参与人员修改
	 */
	public void updatePartRankData(String itemId, List<TPartRank> list, String itemType) {
		// 先删除
//		humanDataDao.deleteTPartRankByCondition(null, itemId);
		draftsDao.deleteTPartRankByCondition(null, itemId);
		// 再插入
		if (list.size() > 0) {
			list.forEach(p -> {
				p.setItemId(itemId);
				p.setId(IdGen.uuid());
				p.setItemType(itemType);
				p.setIsValid(0);// 有效
				draftsDao.addPartRank(p);
			});
		}
	}

	/**
	 * 插入审批流程表
	 */
	public void addWorkFlowData(String businessId, String primitiveId, String auditErpNo, String businessTypeId,
			String fax, String dealRoleCode) {
		TWorkFlow work = new TWorkFlow();
		work.setId(IdGen.uuid());
		work.setBusinessId(businessId);
		work.setDealErpNo(auditErpNo);
		work.setBusinessTypeId(businessTypeId);// 当前业务数据ID
		work.setPrimitiveId(primitiveId);// 原始数据ID，用于和最初的那条数据进行关联
		work.setCreaterId(fax);
//			work.setIsValid(1);
		work.setDelSign(0);
		work.setStatus("0");
		work.setDealRoleCode(dealRoleCode);
//		workFlowDao.saveWorkFlowInfo(work);
	}

	/**
	 * 公共方法--插入操作记录
	 */
	public void addRecordLogData(String recordId, User user, String optType) {
		// 插入操作记录
		TRecordOptLog log = new TRecordOptLog();
		log.setRecordId(recordId);
		if (optType.equals("0")) {// 新增
			log.setOptContent(user.getName() + "新增了数据");
		} else if (optType.equals("2")) {// 编辑
			log.setOptContent(user.getName() + "编辑了数据");
		}
		log.setOptType(optType);
//		recordLogService.save(user, log);
	}

	@Override
	public void addSdtPrentInfo(TSdtPrentInfo p) {
		draftsDao.addSdtPrentInfo(p);
	}

	public boolean judgeTPartRankIsContainCurrentUser(List<TPartRank> ranks, String fax) {
		// 普通人员新增的时候要判断参与人里面有没有当前登录人，如果没有就不允许添加
		boolean flag = false;
		for (TPartRank rank : ranks) {
			if (rank.getErpNo().equals(fax)) {
				flag = true;
			}
		}
		return flag;
	}

	/**
	 * 公共方法--根据原始数据ID删除审批流程表work_flow中之前的审批记录，以防止一条数据在进度查看中展示多次审批记录
	 */
	public void updateWorkFlowDataByPrimitiveId(String primitiveId) {
//		workFlowDao.updateWorkFlowDataByPrimitiveId(primitiveId);
	}

	/**
	 * 公共方法获取审核的角色
	 */
	public String getDealRoleId(String businessTypeId, String orgId) throws Exception {
		TBusinessWorkflowBind tBusinessWorkflowBind = new TBusinessWorkflowBind();
		tBusinessWorkflowBind.setBusinessTypeId(businessTypeId);
		tBusinessWorkflowBind.setOrgId(orgId);
//		List<TBusinessWorkflowBind> list = tBusinessWorkflowBindDao
//				.getDealRoleIdByOrgIdAndBusinessTypeId(tBusinessWorkflowBind);
//		String dealRoleId = null;
//		if (list != null && list.size() > 0) {
//			dealRoleId = list.get(0).getDealRoleId();
//		}
//		return dealRoleId;
		return null;
	}

	/**
	 * 添加挂职轮岗信息
	 * 
	 * @author yangwang
	 * @param tRotationInfo
	 * @param user
	 * @return String
	 */
	@Override
	public String addRotationInfo(TRotationInfo tRotationInfo, User user) throws Exception {
		tRotationInfo.setUpdaterId(user.getFax());
		tRotationInfo.setUpdaterName(user.getName());
//		String dealRoleCode = null;
//		if (user.getRemark().equals("1")) {
//			dealRoleCode = getDealRoleId(t_rotation_info, user.getBaseOrgId());
//			if (StringUtil.isNullOrEmpty(dealRoleCode)) {
//				return "获取审核角色失败";
//			}
//		}
		tRotationInfo.setCreaterId(user.getFax());
		tRotationInfo.setCreaterName(user.getName());
		tRotationInfo.setOrignalId(tRotationInfo.getId());
		tRotationInfo.setPrimitiveId(tRotationInfo.getId());
		tRotationInfo.setBusinessTypeId(t_rotation_info);
		tRotationInfo.setDelSign(0);
		tRotationInfo.setIsValid(1);
		tRotationInfo.setFlowStatus(0);// 要审批
		draftsDao.addRotationInfo(tRotationInfo);
		return null;
	}

	/**
	 * 根据id获取挂职轮岗信息
	 * 
	 * @author yangwang
	 * @param id
	 * @return TRotationInfo
	 */
	@Override
	public TRotationInfo getRotationInfoById(String id) {
		return draftsDao.getRotationInfoById(id);
	}

	/**
	 * 获取挂职轮岗列表信息
	 * 
	 * @author yangwang
	 * @param tRotationInfo
	 * @return List<TRotationInfo>
	 */
	@Override
	public List<TRotationInfo> getListRotationInfoCondi(TRotationInfo tRotationInfo) {
		return draftsDao.getListRotationInfoByCondi(tRotationInfo);
	}

	/**
	 * 获取挂职轮岗分页信息
	 * 
	 * @author yangwang
	 * @param page
	 * @param tRotationInfo
	 */
	@Override
	public void findPageRotationInfoByCondi(Page<TRotationInfo> page, TRotationInfo tRotationInfo) {
		draftsDao.findPageRotationInfoByCondi(page, tRotationInfo);
	}

	/**
	 * 获取挂职轮岗待审核信息
	 * 
	 * @author yangwang
	 * @param id
	 * @return List<TRotationInfo>
	 */
	@Override
	public List<TRotationInfo> getReadyRotationInfoById(String id) {
		return draftsDao.getReadyRotationInfoById(id);
	}

	@Override
	public List<TSdtPrentInfo> getTSdtPrentInfoListById(String id) {
		return draftsDao.getTSdtPrentInfoListById(id);
	}

	@Override
	public void addSdtAwardInfo(TSdtAward tSdtAward) {
		draftsDao.addSdtAwardInfo(tSdtAward);
	}

	@Override
	public void updateEducateInfoYes(TEducateInfo educateInfo, User user) {
		draftsDao.updateEducateInfoYes(educateInfo, user);
	}

	@Override
	public void updateContiStudyInfo(TContiStudyInfo contiStudyInfo, User user) {
		if (user != null) {
			contiStudyInfo.setUpdaterId(user.getFax());
			contiStudyInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateContiStudyInfo(contiStudyInfo);
	}

	@Override
	public void updateProTecInfo(TProTecInfo proTecInfo, User user) {
		if (user != null) {
			proTecInfo.setUpdaterId(user.getFax());
			proTecInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTProTecInfo(proTecInfo);
	}

	@Override
	public void updateTSkillLevelInfo(TSkillLevelInfo skillLevelInfo, User user) {
		if (user != null) {
			skillLevelInfo.setUpdaterId(user.getFax());
			skillLevelInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTSkillLevelInfo(skillLevelInfo);
	}

	@Override
	public void updateTExpertTitleInfo(TExpertTitleInfo tExpertTitleInfo, User user) {
		if (user != null) {
			tExpertTitleInfo.setUpdaterId(user.getFax());
			tExpertTitleInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTExpertTitleInfo(tExpertTitleInfo);
	}

	@Override
	public void updateTAcadeAchiveInfo(TAcadeAchiveInfo tAcadeAchiveInfo, User user) {
		if (user != null) {
			tAcadeAchiveInfo.setUpdaterId(user.getFax());
			tAcadeAchiveInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTAcadeAchiveInfo(tAcadeAchiveInfo);
	}

	@Override
	public void updateTStandInfo(TStandInfo tStandInfo, User user) {
		if (user != null) {
			tStandInfo.setUpdaterId(user.getFax());
			tStandInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTStandInfo(tStandInfo);
	}

	@Override
	public void updateTPatentInfo(TPatentInfo tPatentInfo, User user) {
		if (user != null) {
			tPatentInfo.setUpdaterId(user.getFax());
			tPatentInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTPatentInfo(tPatentInfo);
	}

	@Override
	public void updateTTecInnovInfo(TTecInnovInfo tTecInnovInfo, User user) {
		if (user != null) {
			tTecInnovInfo.setUpdaterId(user.getFax());
			tTecInnovInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTTecInnovInfo(tTecInnovInfo);
	}

	@Override
	public void updateTContestInfo(TContestInfo tContestInfo, User user) {
		if (user != null) {
			tContestInfo.setUpdaterId(user.getFax());
			tContestInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTContestInfo(tContestInfo);
	}

	@Override
	public void updateTTecManInnov(TTecManInnov tTecManInnov, User user) {
		if (user != null) {
			tTecManInnov.setUpdaterId(user.getFax());
			tTecManInnov.setUpdaterName(user.getName());
		}
		draftsDao.updateTTecManInnov(tTecManInnov);
	}

	@Override
	public void updateTHonorInfo(THonorInfo tHonorInfo, User user) {
		if (user != null) {
			tHonorInfo.setUpdaterId(user.getFax());
			tHonorInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTHonorInfo(tHonorInfo);
	}

	@Override
	public void updateTProjAchieveInfo(TProjAchieveInfo tProjAchieveInfo, User user) {
		if (user != null) {
			tProjAchieveInfo.setUpdaterId(user.getFax());
			tProjAchieveInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTProjAchieveInfo(tProjAchieveInfo);
	}

	@Override
	public void updateTSdtTutorPrentInfo(TSdtTutorPrentInfo tSdtTutorPrentInfo, User user) {
		if (user != null) {
			tSdtTutorPrentInfo.setUpdaterId(user.getFax());
			tSdtTutorPrentInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTSdtTutorPrentInfo(tSdtTutorPrentInfo);
	}

	@Override
	public void deleteTSdtAwardBySdtTdId(String id) {
		draftsDao.deleteTSdtAwardBySdtTdId(id);
	}

	@Override
	public void deleteTSdtPrentInfoByCondition(String orgId, String id) {
		draftsDao.deleteTSdtPrentInfoByCondition(null, id);
	}

	@Override
	public void updateTWorkExpInfo(TWorkExpInfo tWorkExpInfo, User user) {
		if (user != null) {
			tWorkExpInfo.setUpdaterId(user.getFax());
			tWorkExpInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTWorkExpInfo(tWorkExpInfo);
	}

	@Override
	public void updateTRotationInfo(TRotationInfo tRotationInfo, User user) {
		if (user != null) {
			tRotationInfo.setUpdaterId(user.getFax());
			tRotationInfo.setUpdaterName(user.getName());
		}
		draftsDao.updateTRotationInfo(tRotationInfo);
	}

	@Override
	@Transactional
	public void deleteMes(String businessId, String tabName) {
		//先删除草稿箱列表数据
		draftsDao.deleteDraftsListByBusinessId(businessId);
		draftsDao.deleteMes(businessId, tabName);
		if ("t_acade_achive_info_drafts".equals(tabName) || "t_stand_info_drafts".equals(tabName)
				|| "t_patent_info_drafts".equals(tabName) || "t_tec_innov_info_drafts".equals(tabName)
				|| "t_tec_man_innov_drafts".equals(tabName) || "t_proj_achieve_info_drafts".equals(tabName)) {
			draftsDao.deletePartRankData(businessId);
		} else if ("t_sdt_tutor_prent_info_drafts".equals(tabName)) {
			// 先删除徒弟所获奖项信息
			List<TSdtPrentInfo> prentInfos = draftsDao.getTSdtPrentInfoListById(businessId);
			if (prentInfos != null && prentInfos.size() > 0) {
				prentInfos.forEach(p -> {
					draftsDao.deleteTSdtAwardBySdtTdId(p.getId());
				});
			}
			// 再删除徒弟信息
			draftsDao.deleteTSdtPrentInfoByCondition(null, businessId);
		}
	}

	@Override
	public Map<String,Long> integrityAnalysis(List<TMouldInfo> list, String erpNo) {
		int allCount = list.size();
		double i = 0;
		Iterator<TMouldInfo> it = list.iterator();
		TMouldInfo m = null;
		IntegrityAnalysisVo entity =null;
		Map<String,Long> map=new HashMap<String,Long>();
        while (it.hasNext()) {
            m = it.next();
            if((null != m)&&(StringUtils.isNotBlank(m.getId()))) {
            	if ("t_acade_achive_info".equals(m.getTabName()) || "t_stand_info".equals(m.getTabName())
    					|| "t_patent_info".equals(m.getTabName()) || "t_tec_innov_info".equals(m.getTabName())
    					|| "t_tec_man_innov".equals(m.getTabName()) || "t_proj_achieve_info".equals(m.getTabName())) {
    				int itemType=m.getType();
    				entity = draftsDao.integrityAnalysisByTypeAndErpNo(itemType, erpNo,m.getTabName());
    			}else {
    				entity = draftsDao.integrityAnalysisByTabNameAndErpNo(m.getTabName(), erpNo);
    			}
            	if(entity!=null) {
            		map.put(m.getTabName(), entity.getCountNum());
            	}
            	if (entity == null || entity.getCountNum() <= 0) {
					it.remove();
				}
            }else {
            	it.remove();
            }
        }
//		for (TMouldInfo m : list) {
//			String tabName = m.getTabName();
//			if ("t_acade_achive_info".equals(tabName) || "t_stand_info".equals(tabName)
//					|| "t_patent_info".equals(tabName) || "t_tec_innov_info".equals(tabName)
//					|| "t_tec_man_innov".equals(tabName) || "t_proj_achieve_info".equals(tabName)) {
//				int itemType=m.getType();
//				IntegrityAnalysisVo entity = draftsDao.integrityAnalysisByTypeAndErpNo(itemType, erpNo);
//				if (entity != null && entity.getCountNum() > 0) {
//					i++;
//				}
//			}else {
//				IntegrityAnalysisVo entity = draftsDao.integrityAnalysisByTabNameAndErpNo(tabName, erpNo);
//				if (entity != null && entity.getCountNum() > 0) {
//					i++;
//				}
//			}
//		}
		double rs=(double)list.size()/allCount;
		BigDecimal b =new BigDecimal(rs);
		double f=b.setScale(2, RoundingMode.HALF_UP).doubleValue()*100;
		map.put("integrity", (long)f);
		return map;
	}

	@Override
	public void addDraftsList(DraftsListVo draftsList, User user) {
		draftsList.setCreaterId(user.getFax());
		draftsList.setCreaterName(user.getName());
		draftsList.setUpdaterId(user.getFax());
		draftsList.setUpdaterName(user.getName());
		draftsDao.addDraftsList(draftsList);
	}

	@Override
	public void getDraftsListPage(Page<DraftsListVo> page,String erpNo) {
		draftsDao.getDraftsListPage(page,erpNo);
	}

	@Override
	public void deleteDraftsListByBusinessId(String businessId) {
		draftsDao.deleteDraftsListByBusinessId(businessId);
	}
	
	@Override
	public void addGrowthPlan(TGrowthPlan tGrowthPlan, User user) {
		draftsDao.addGrowthPlan(tGrowthPlan,user);
	}

	@Override
	public void getPersonalPageGrowthPlanByErpNo(Page<TGrowthPlan> page, String erpNo) {
		draftsDao.getPersonalPageGrowthPlanByErpNo(page,erpNo);
	}

	@Override
	public TGrowthPlan getGrowthPlanById(String id) {
		return draftsDao.getGrowthPlanById(id);
	}

	@Override
	public void updateGrowthPlan(TGrowthPlan tGrowthPlan, User user) {
		draftsDao.updateGrowthPlan(tGrowthPlan,user);
	}


	@Override
	@Transactional
	public void addEmployeeMobility(TEmployeeMobility employeeMobility, User user) {
		//员工流动草稿箱添加数据
		employeeMobility.setBusinessTypeId(t_employee_mobility);
		draftsDao.addEmployeeMobility(employeeMobility, user);
		//往草稿箱列表添加数据
		DraftsListVo draftsList = new DraftsListVo();
		draftsList.setBusinessId(employeeMobility.getId());
		draftsList.setTypeId(employeeMobility.getBusinessTypeId());
		TMouldInfo tMouldInfo = new TMouldInfo();
		tMouldInfo.setId(t_employee_mobility);
		List<TMouldInfo> list = userInfoService.getMouldInfoList(tMouldInfo);
		if (list != null && list.size() > 0) {
			draftsList.setTypeName(list.get(0).getMouldName());
		}
		addDraftsList(draftsList, user);
	}

	@Override
	public void findPageEmployeeMobilityByCondi(Page<TEmployeeMobility> page, TEmployeeMobility employeeMobility) {
		draftsDao.findPageEmployeeMobilityByCondi(page, employeeMobility);
		if (!page.getResult().isEmpty()) {
			page.getResult().forEach(p -> {
				p.setFlowAreaStr(SysDictionaryUtil.getNameByValueForDefault("FlowArea", p.getFlowArea()));
				p.setFlowTypeStr(SysDictionaryUtil.getNameByValueForDefault("FlowType", p.getFlowType()));
				p.setFlowModeStr(SysDictionaryUtil.getNameByValueForDefault("FlowMode", p.getFlowMode()));
			});
		}
	}

	@Override
	public TEmployeeMobility getEmployeeMobilityById(String id) {
		return draftsDao.getEmployeeMobilityById(id);
	}

	@Override
	public void updateEmployeeMobility(TEmployeeMobility employeeMobility) {
		employeeMobility.setBusinessTypeId(t_employee_mobility);
		draftsDao.updateEmployeeMobility(employeeMobility);
	}

	/**
	 * 获取技术标准信息
	 *
	 * @param tecStandardInfo
	 * @return List<TRotationInfo>
	 * @author pengmengzhi
	 */
	@Override
	public void findPageTecStandardInfoByCondi(Page<TTecStandardInfo> page, TTecStandardInfo tecStandardInfo) {
		draftsDao.findPageTecStandardInfoByCondi(page, tecStandardInfo);
		if (!page.getResult().isEmpty()) {
			List<TTecStandardInfo> tecStandardInfoVos = page.getResult();

			List<String> ids = new ArrayList<>();
			tecStandardInfoVos.forEach(i -> ids.add(i.getId()));
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(ids, "21");
			if (!tPartRankList.isEmpty()) {
				for (TTecStandardInfo tecStandardInfoVo : tecStandardInfoVos) {
					List<TPartRank> tPartRankListVo = new ArrayList<>();
					for (TPartRank tPartRank : tPartRankList) {
						if (tecStandardInfoVo.getId().equals(tPartRank.getItemId())) {
							tPartRankListVo.add(tPartRank);
						}
					}
					tecStandardInfoVo.settPartRankList(tPartRankListVo);
				}
			}
		}
	}

	@Override
	public void addTecStandardInfo(TTecStandardInfo tecStandardInfo, User user) {
		tecStandardInfo.setUpdaterId(user.getFax());
		tecStandardInfo.setUpdaterName(user.getName());
		List<TPartRank> ranks = tecStandardInfo.gettPartRankList();
		tecStandardInfo.setOrgId(user.getBaseOrgId());
		tecStandardInfo.setCreaterId(user.getFax());
		tecStandardInfo.setCreaterName(user.getName());
		tecStandardInfo.setOrignalId(tecStandardInfo.getId());
		tecStandardInfo.setPrimitiveId(tecStandardInfo.getId());
		tecStandardInfo.setBusinessTypeId(t_tec_standard_info);
		tecStandardInfo.setDelSign(0);
		tecStandardInfo.setIsValid(0);
		tecStandardInfo.setFlowStatus(0);// 要审批
		draftsDao.addTecStandardInfo(tecStandardInfo);
		addPartRank(ranks, tecStandardInfo.getId(), "21");

		//往草稿箱列表添加数据
		DraftsListVo draftsList = new DraftsListVo();
		draftsList.setBusinessId(tecStandardInfo.getId());
		draftsList.setTypeId(tecStandardInfo.getBusinessTypeId());
		TMouldInfo tMouldInfo = new TMouldInfo();
		tMouldInfo.setId(t_tec_standard_info);
		List<TMouldInfo> list = userInfoService.getMouldInfoList(tMouldInfo);
		if (list != null && list.size() > 0) {
			draftsList.setTypeName(list.get(0).getMouldName());
		}
		addDraftsList(draftsList, user);
	}

	@Override
	public TTecStandardInfo getTecStandardInfoById(String id){
		TTecStandardInfo tecStandardInfo = draftsDao.getTecStandardInfoById(id);
		if (tecStandardInfo != null) {
			List<TPartRank> tPartRankList = draftsDao.getTPartRankByMids(new ArrayList<String>() {
				{
					add(id);
				}
			}, "21");
			tecStandardInfo.settPartRankList(tPartRankList);
		}
		return tecStandardInfo;
	}

	@Override
	public int updateTecStandardInfo(TTecStandardInfo tecStandardInfo,User user){
		if (user != null) {
			tecStandardInfo.setUpdaterId(user.getFax());
			tecStandardInfo.setUpdaterName(user.getName());
		}
		return draftsDao.updateTecStandardInfo(tecStandardInfo);
	}

}